<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/css/style.css" type="text/css" media="all" />
<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/artdialog/skins/default.css" type="text/css" media="all" />
<link href="<?php echo URL::base() ?>media/vendor/css/ui-lightness/jquery-ui-1.10.4.custom.css" rel="stylesheet">
<link href="<?php echo URL::base() ?>media/vendor/fixtable/css/component.css" rel="stylesheet">
<link href="<?php echo URL::base() ?>media/vendor/fixtable/css/normalize.css" rel="stylesheet">
<link href="<?php echo URL::base() ?>media/vendor/css/jquery-ui-timepicker-addon.min.css" rel="stylesheet">
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-1.7.1.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.core.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.widget.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.position.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.autocomplete.min.js"></script> 
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-1.7.1.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-1.10.4.custom.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-timepicker-addon.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-timepicker-zh-CN.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.datepicker-zh-TW.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/Validform_v5.3.2_ncr_min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/artdialog/jquery.artDialog.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/fixtable/js/jquery.ba-throttle-debounce.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/fixtable/js/jquery.stickyheader.js"></script>
<style>
.overflow-y td,.overflow-y th{
font-size: 12px;
min-width: 150px;
text-align: center;
}
.forhide{ 
 display:none; 
}
#down{margin-left:6px} 
.mypage{display: none;}
.mypage .num{color: red;}
.form-horizontal .control-label{ width:80px;}
.form-horizontal .controls{ margin-left:90px;}
</style>
<script type="text/javascript">
page=0;
pagenum=100;
function page_load(url,method){
	var dialog = art.dialog({title: '提示',icon:'question',lock: true});
	dialog.content('<p>数据查询中,请稍后...<p>');
	$.get(
		url,
		{
			sku: $.trim($("input[name=sku]").val()),
	    	per_page: page,
    	    sortcondition: $(".form-horizontal select[name='sortcondition']").val(),
    	    order: $(".form-horizontal select[name='order']").val(),
		},
		function(data){
			if(method=='search'){
				$('#table_content').empty();
				page=1;
			}
			$(data).appendTo('#table_content');
			$('#pager_links').empty();
	        $($('.mypage').get(0)).clone().appendTo('#pager_links').show();
	        $('#table_content .remove').remove();
			dialog.close();
		}
	);	
}
$(function(){
	$('#search').click(function(){
		var sku=$.trim($("input[name=sku]").val());
		if(sku!=''){
			var stamp=0;
			$.ajax({
				type:'post',
				url:'<?php echo url::base(true);?>inventory/deliverycheck/checksku',
				dataType:'json',
				data:{param:sku},
				async:false,
				success:function(data){
					if(data.status=='y'){
			    	}else{
			    		stamp = 1;
				    	alert('未找到SKU为 '+data.sku+' 的对应信息');return;
			    	}
				},
				error:function(){
					alert('错误');
				},
			});
			if(stamp==1)return;
		}
		url='<?php echo url::base();?>report/sale/sale_load';
		page_load(url,$(this).attr('id'));
	});
	$("#load").click(function(){
		var num=$('#pager_links .num').text();
		page++;
        if(num<(page-1)*pagenum){
			var dialog = art.dialog({title: '提示',icon:'question',lock: true});
			dialog.content('<p>数据已经加载完成<p>');
		}else{
			url='<?php echo url::base();?>report/sale/sale_load?page='+page;
			page_load(url,$(this).attr('id'));
		}
	});
	$("#down").click(function(){
		var sku=$.trim($("input[name=sku]").val());
	    var sortcondition=$(".form-horizontal select[name='sortcondition']").val();
	    var order=$(".form-horizontal select[name='order']").val();
		var uri='sku='+sku+'&sortcondition='+sortcondition+'&order='+order;
		window.location.href="<?php echo URL::base()?>report/sale/down?"+uri;
	});
});
</script>
<div class="row" style="margin-top: 25px;">
		<div class="span11">
			<form class="form-horizontal" >
    	      	<div class="control-group " id="sku">
    	      		<label class="control-label w-label">SKU:</label>
					<div class="controls">
						<input type="text"  name='sku' value=""> 
					</div>
				</div>
				<div class="control-group">
					<label class="control-label w-label">排序条件:</label>
					<div class="controls">
						<select  name='sortcondition'>
							<option value="daysales7">选择（默认7天）</option>
							<option value='daysales7'>7天</option>
							<option value='daysales14'>14天</option>
							<option value='daysales21'>21天</option>
							<option value='daysales28'>28天</option>
						</select>
					</div>
				</div>
					<div class="control-group">
					<label class="control-label w-label">排序方式:</label>
					<div class="controls">
						<select name='order' >
						    <option value='2'>降序</option>
							<option value='1'>升序</option>
						</select>
					</div>
				</div>
				<div class="control-group">
					<div style="margin-top:15px;margin-left:110px;">
						<div class="btn btn-info" id="search">查询</div>
						<input type="reset" style="margin-left:5px;" class="btn btn-inverse" value="重置">
						<div id="down" class="btn btn-success"><a class="download" style="color:#FFF;">下载</a></div>
					</div>
				</div>
			</form>
			<table class="sticky-wrap overflow-y">
              <thead>
                <tr>
                  <th>SKU</th>
                  <th>中文名称</th>
                  <th>日均销量</th>
                  <th>7天销量</th>
                  <th>14天销量</th>
                  <th>21天销量</th>
                  <th>28天销量</th>
                  <th>采购定价单价</th>
                  <th>供应商最低采购价</th>
                </tr>
              </thead>
              <tbody id='table_content'>
              </tbody>
            </table>
            <div id="pager_links"></div>
		</div>
		<div class="span2"></div>
	</div>
<div class="btn btn-success" id='load'><a style="color:#FFF" >继续加载100条</a></div>	